package jdbc1;
import com.mysql.cj.jdbc.Driver;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class TestSelect {
    public static void main(String[] args) {
        try {
            //static{}执行了
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        //ip信息，端口，库名，其他参数
        //jdbc:mysql://localhost:3308/java83
        String url="jdbc:mysql://localhost:3308/java83?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai";
        try {
            Connection con = DriverManager.getConnection(url, "xukang", "Xu1234");
            System.out.println(con.getClass().getName());
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery("select * from s_subject order by id desc limit 40");
            while (rs.next()){
                long id = rs.getLong("id");
                String name=rs.getString("subjectname");
                int hour=rs.getInt("classhour");
                long gid=rs.getLong("gradeid");
                System.out.println(id+","+name+","+hour+","+gid);
            }
            rs.close();
            st.close();
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
